/**
 * 功能描述 行编辑触发事件
 */
define(function (require, exports, module) {
	var store = require("store");
	var activeUser = store.get("user");
	var aw = require("ajaxwrapper");
	var Dialog=require("dialog");
	
    module.exports = {
        addApply : function(widget){
        	
        	var formData = widget.get("form").getData();
        	
        	if(!formData.signUpStatus && formData.limitmax=="true" && formData.limitmin=="true" && parseInt(formData.countMember)>=parseInt(formData.maxpeople)){
    			Dialog.alert({
            		title:"报名失败",
            		content:"报名人数已到上限，无法报名！"
            	});
        		return false;
    		}
        	
        	
        	var applyForm = widget.get("applyForm");
        	widget.hide([".J-form", ".J-applygrid",".J-editgrid"]).show(".J-applyform");
			widget.get("subnav").hide(["travelDate","destination", "servicePoint","cancel","applyCancel","save"]);
			applyForm.reset();
			var autocomplete =  $("input[name='travelContractObj']",applyForm.element).data("autocompleter");
			autocomplete.setExtraParam("pkServicePoint",widget.get("subnav").getValue("servicePoint"));
			applyForm.show("personalInfo.name").hide("memberObj");
			
			var pkPlanItem = widget.get("form").getValue("pkPlanItem");
			var pkServicePoint = widget.get("form").getValue("pkServicePoint");
			applyForm.setValue("pkPlanItem",pkPlanItem);
			applyForm.setValue("pkServicePoint",pkServicePoint);
			
        },
        editApply : function(data, widget){
        	var applyForm = widget.get("applyForm");
        	
        	widget.hide([".J-form", ".J-applygrid",".J-editgrid"]).show(".J-applyform");
			widget.get("subnav").show(["applyCancel"]).hide(["travelDate", "destination", "servicePoint","cancel","save"]);
			applyForm.reset();
			applyForm.setData(data);
			var pkPlanItem = widget.get("form").getValue("pkPlanItem");
			var pkServicePoint = widget.get("form").getValue("pkServicePoint");
			applyForm.setValue("pkPlanItem",pkPlanItem);
			applyForm.setValue("pkServicePoint",pkServicePoint);
			
			applyForm.setValue("travelContractObj",data.travelContract);
			applyForm.setValue("pkTravelContract",data.travelContract.pkTravelContract);
			
			var memberObj = {
				personalInfo:data.personalInfo
			};
			applyForm.setValue("memberObj",memberObj);
			
			if(data.member == "false" || data.member==false){
				applyForm.hide("memberObj").show("personalInfo.name");
			}else{
				applyForm.show("memberObj").hide("personalInfo.name");
				applyForm.setReadonly("personalInfo.idNumber",true);
				applyForm.setReadonly("personalInfo.mobilePhone",true);
				applyForm.setReadonly("personalInfo.sex",true);
			}

			var autocomplete =  $("input[name='travelContractObj']",applyForm.element).data("autocompleter");
			autocomplete.setExtraParam("pkServicePoint",widget.get("subnav").getValue("servicePoint"));
			
        },
        deleteApply:function(data,widget){
        	aw.del("api/signupregister/"+data.pkSignUpRegister+"/delete",function(data){
        		widget.get("applyGrid").refresh(null,function(data){
					widget.get("form").setValue("countMember",data.length);	
				});
        	});
        }
    };
});
